<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Item_model extends CI_Model {


    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
        $this->load->database();
    }
    function getListItemByCategoryId($categoryId){
        $mysql = "SELECT * FROM item WHERE product_id = $categoryId ";
        $data = $this->db->query($mysql);
        return $data->result_array();
    }
    
    function getAllItemByCategoryId($categoryId, $perpage, $numrow)
    {
        
        $mysql = "SELECT * FROM item WHERE product_id = $categoryId LIMIT $numrow, $perpage ";
        $data = $this->db->query($mysql);
        return $data->result_array();
        
    }
    /**
    * list item by itemId
    * 
    * @param type $type
    */
    function getItemById($id)
    {
        $mysql = "SELECT * FROM item WHERE id = $id";
        $data = $this->db->query($mysql);
        return $data->row_array();
    }
    //--------------------
    /**
     * @author Ngoc Thiep
     * @email nnthieps@gmail.com
     * @param type $type 
     * @deprecated get list cac nhom san pham
     */
    function getGroupProduct($type){
        $mysql = "SELECT * FROM product WHERE type = $type ";
        $data = $this->db->query($mysql);
        return $data->result_array();
    }
    
    /**
     * list all category 
     */
    function listAllProduct(){
        $mysql = "SELECT * FROM product";
        $data = $this->db->query($mysql);
        return $data->result_array();
    }
    
    function insert($array)
    {
        
        $data = array(
            'product_id' =>$array['product_id'],
            'name_vn' => $array['name_vn'],
            'name_en' => $array['name_en'],
            'name_jp' => $array['name_jp'],
            
            'image_src' => $array['image_src'],
            
            'content_vn' => $array['content_vn'],
            'content_en' => $array['content_en'],
            'content_jp' => $array['content_jp'],
            
            'summary_vn' => $array['summary_vn'],
            'summary_en' => $array['summary_en'],
            'summary_jp' => $array['summary_jp'],

            'order_id' => $array['order_id'],
            'create_time'=>time(),
        );
        $this->db->insert('item', $data);
        $id = $this->db->insert_id();
        return $id;
    }
    /**
    * get category by product_id
    * 
    * @param mixed $id
    */
    function getProductById($id)
    {
        $mysql = "SELECT * FROM product WHERE id = $id";
        $data = $this->db->query($mysql);
        return $data->row_array();
    }

    /** 
    * update product by id
    * 
    */
    function update($array)
    {
        $data = array(
            'product_id' =>$array['product_id'],
            'name_vn' => $array['name_vn'],
            'name_en' => $array['name_en'],
            'name_jp' => $array['name_jp'],
            
            'image_src' => $array['image_src'],
            
            'content_vn' => $array['content_vn'],
            'content_en' => $array['content_en'],
            'content_jp' => $array['content_jp'],
            
            'summary_vn' => $array['summary_vn'],
            'summary_en' => $array['summary_en'],
            'summary_jp' => $array['summary_jp'],

            'order_id' => $array['order_id'],
            'create_time' =>  time(),
        );
        $this->db->where('id', $array['id']);
        $this->db->update('item', $data);
    }
    /**
    * delete productId
    * 
    * @param mixed $id
    */
    function delete($id) {
        $this->db->where('id', $id);
        $this->db->delete('item');
    }

}
?>
